package com.winit.openapi.tms.validator;

import com.alibaba.fastjson.JSONObject;
import com.winit.openapi.tms.constant.BookingConstant;
import com.winit.openapi.util.ValidateUtil;

/**
 * 预约单校验类
 * 
 * @version <pre>
 * Author	Version		Date		Changes
 * ming.chen 	1.0  		2017-9-26 	Created
 * 
 * </pre>
 * @since 1.
 */
public class BookingOrderValidator {

    /**
     * 创建预约单校验
     * 
     * @param json
     */
    public static void validCreateBookingOrderField(JSONObject json) {
        validBookingOrderField(json);
    }

    private static void validBookingOrderField(JSONObject json) {
        // 派送方式
        ValidateUtil.validNotNull(json, "deliveryWayType");

        String deliveryWayType = json.getString("deliveryWayType");
        if (BookingConstant.DeliveryWayType.FCL.getType().equals(deliveryWayType)) {
            // 是否打托
            ValidateUtil.validNotNull(json, "isPallet");
            String isPallet = json.getString("isPallet");

            // 选择是打托
            if (BookingConstant.IS_PALLET_Y.equals(isPallet)) {
                // 打托数
                ValidateUtil.validNotNull(json, "palletQty");
                ValidateUtil.validMaxLength(json, "palletQty", 9);
            }

            // 柜型名称
            ValidateUtil.validNotNull(json, "cabinetType");
            // 集装箱号
            ValidateUtil.validNotNull(json, "containerNo");
            // 卸货方式
            ValidateUtil.validNotNull(json, "unloadType");
            // 封条号
            ValidateUtil.validMaxLength(json, "sealNo", 50);
            // 联系人
            ValidateUtil.validMaxLength(json, "contactPerson", 100);
            // 联系电话
            ValidateUtil.validMaxLength(json, "contactNumper", 100);
            // 邮件
            ValidateUtil.validMaxLength(json, "email", 100);
        } else if (BookingConstant.DeliveryWayType.LCL.getType().equals(deliveryWayType)) {
            // 关联单号
            ValidateUtil.validMaxLength(json, "referenceNo", 50);
            // 联系人
            ValidateUtil.validMaxLength(json, "contactPerson", 100);
            // 联系电话
            ValidateUtil.validMaxLength(json, "contactNumper", 100);
            // 邮件
            ValidateUtil.validMaxLength(json, "email", 100);
            // 供应商编码
            ValidateUtil.validMaxLength(json, "supplierCode", 32);
            // 供应商名称
            ValidateUtil.validMaxLength(json, "supplierName", 128);
        } else if (BookingConstant.DeliveryWayType.Express.getType().equals(deliveryWayType)) {
            // 快递单号
            ValidateUtil.validNotNull(json, "trackingNo");
            ValidateUtil.validMaxLength(json, "trackingNo", 32);
            // 供应商编码
            ValidateUtil.validNotNull(json, "supplierCode");
            ValidateUtil.validMaxLength(json, "supplierCode", 32);
            // 供应商名称
            ValidateUtil.validNotNull(json, "supplierName");
            ValidateUtil.validMaxLength(json, "supplierName", 128);
        }

    }
}
